<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Models\User;

class UserController extends Controller
{
    use ModelForm;
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header('用户');
            $content->description('管理');
            $content->body($this->grid());
        });
    }

    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {
            $content->header('用户');
            $content->description('编辑');

            $content->body($this->form()->edit($id));
        });
    }

    public function create()
    {
        return Admin::content(function (Content $content) {
            $content->header('用户');
            $content->description('创建');

            $content->body($this->form());
        });
    }

    protected function grid()
    {
        return Admin::grid(User::class, function (Grid $grid) {
            // $grid->position_tags('轮播图序号');
            $grid->id('序号');
            // $grid->name('用户呢称');
            // $grid->avatar('用户头像')->image();
            // $grid->phone_number('用户手机号');
            // $grid->email('用户邮箱');
            $grid->openid('用户openid');
            // $grid->weixin_session_key('用户weixin_session_key');
            // $is_member = [
            // 'on' => ['value' => '1', 'text' => '会员', 'color' => 'success'],
            // 'off' => ['value' => '0', 'text' => '非会员', 'color' => 'danger'],
            // ];
            // $grid->column('is_member','会员与否')->switch($is_member);
            $grid->disableFilter();
            $grid->disableExport();
            // $grid->disableCreateButton();
            // $grid->disablePagination();
            $grid->disableFilter();
            $grid->paginate(10);
            $grid->perPages([10,20,30]);
            $grid->disableRowSelector();
            $grid->disableCreateButton();
            $grid->disableActions();
            $grid->actions(function ($actions) {
                // $actions->disableDelete();
                $actions->disableDelete();
            });
        });
    }

    protected function form()
    {
        return Admin::form(User::class, function (Form $form) {
            // $form->text('position_tags', '轮播图位置');
            // $form->text('name', '用户名称');
            // $form->text('avatar', '用户头像');
            // $form->text('phone_number', '用户手机号');
            // $form->text('email', '用户邮箱');
            $form->text('openid', 'openid');
            // $form->text('weixin_session_key', 'weixin_session_key');
//             $states = [
//  'on'  => ['value' => 1, 'text' => '会员', 'color' => 'success'],
//  'off' => ['value' => 0, 'text' => '非会员', 'color' => 'danger'],
// ];
//             $form->switch("is_member","会员设置")->states($states);
        });
    }
  }
